package cn.wolfcode.luowowo2.mgrsite.web.controller;

import cn.wolfcode.luowowo2.article.domain.Strategy;
import cn.wolfcode.luowowo2.article.domain.StrategyCatalog;
import cn.wolfcode.luowowo2.article.service.IStrategyCatalogService;
import cn.wolfcode.luowowo2.article.service.IStrategyService;
import cn.wolfcode.luowowo2.common.query.StrategyCatalogQueryObject;
import cn.wolfcode.luowowo2.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Albert on 2019/7/9.
 */
@Controller
@RequestMapping("strategyCatalog")
public class StrategyCatalogController {
    @Reference
    private IStrategyCatalogService strategyCatalogService;

    @Reference
    private IStrategyService strategyService;

    @RequestMapping("list")
    public String list(Model model,@ModelAttribute("qo") StrategyCatalogQueryObject qo){
        PageInfo<StrategyCatalog> pageInfo = strategyCatalogService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        List<Strategy> strategyList =strategyService.listAll();
        model.addAttribute("strategies",strategyList);

        return "strategyCatalog/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(StrategyCatalog strategyCatalog){
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return new AjaxResult();
    }
}
